import com.alibaba.fastjson.JSON;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;

public class Players {
    //输出选手信息
    public static void showPlayers() {
        String json = "src/data/players.json";
        File jsonFile = new File(json);
        String jsonData;
        jsonData = IO.getStr(jsonFile);
        //将json字符串处理为json对象列表
        List<HashMap> list = JSON.parseArray(jsonData, HashMap.class);

        //遍历json对象列表
        if (list != null) {
            for (HashMap hashMap : list) {
                //读取json对象中的json数组
                List<HashMap> items = JSON.parseArray(hashMap.get("Participations").toString(), HashMap.class);
                for (HashMap hashMapItems : items){
                    System.out.print("full_name:");
                    System.out.print(hashMapItems.get("PreferredFirstName"));
                    System.out.println(" " + hashMapItems.get("PreferredLastName"));

                    System.out.print("Gender:");
                    if (hashMapItems.get("Gender").equals(0)) {
                        System.out.println("male");
                    } else {
                        System.out.println("female");
                    }

                    System.out.print("Country:");
                    System.out.println(hashMap.get("CountryName"));

                    System.out.println("-----");
                }
            }
        }
    }
}
